package com.kefu.chat.mapper;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.kefu.chat.model.ChatFaqGroup;
import com.kefu.common.mybatis.KefuMapper;

import java.util.List;

public interface ChatFaqGroupMapper extends KefuMapper<ChatFaqGroup> {
    /**
     * 是否存在相同的名称
     * @param name
     * @param tenantId
     * @param exceptGroupId except
     * @return
     */
    default boolean existGroupName(String name, String tenantId, String exceptGroupId){
        LambdaQueryWrapper<ChatFaqGroup> query= Wrappers.lambdaQuery();
        query.eq(ChatFaqGroup::getTenantId,tenantId);
        query.eq(ChatFaqGroup::getFaqGroupName,name);
        query.ne(StrUtil.isNotBlank(exceptGroupId),ChatFaqGroup::getId,exceptGroupId);

        return selectCount(query)>0;
    }
}
